package com.itheima.util;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author chenry
 * @Package com.itheima.util
 * @Date 2025/2/23 18:28
 */
public class FullcarbillTraceThreadPoolUtil {
    private static final int CORE_THREAD_NUM = 10;
    private static final int MAX_THREAD_NUM = 100;//最大线程数
    private static final int KEEP_ALIVE_TIME = 30;//非核心线程存活时间
    private static final int ARRAY_BLOCKING_QUEUE_SIZE = 1000;//最大等待线程数

    private static ExecutorService executor = new ThreadPoolExecutor(CORE_THREAD_NUM, MAX_THREAD_NUM, KEEP_ALIVE_TIME, TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(ARRAY_BLOCKING_QUEUE_SIZE),
            new ThreadFactoryBuilder().setNameFormat("wlhy-thread-%d").build(),
            new ThreadPoolExecutor.CallerRunsPolicy());

    public static ExecutorService getWlhyThreadPoolExecutor() {
        return executor;
    }
    private FullcarbillTraceThreadPoolUtil() {
        // 防止实例化，什么都不需要做
        throw new AssertionError("No instances for you!"); // 可以选择抛出异常，但这不是必须的
    }

}
